【Ansible】UNREACHABLE!: Failed to create temporary directory の原因と対処



ansible コントロールノードから Windows 10 PC へ ansible コマンドを実行したところ以下のエラーが発生しました。PC名は "winpc" にしています。


# ansible winpc -i inventory -m ping -o --ask-pass --user=username
SSH password:
winpc | UNREACHABLE!: Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "` echo ~/.ansible/tmp `"&& mkdir "` echo ~/.ansible/tmp/ansible
(中略)



エラーメッセージの中身を見ると、ssh クライアントでリモートにフォルダがないことが原因であることが分かります。

Consider changing the remote tmp path in ansible.cfg



しかし ansible ではなく ssh クライアントで接続すると、ホームディレクトリが存在していることが分かります。
以下コマンドでログインしてら"C:\Users\username"に移動できました。

ssh username@192.168.11.100



原因


Windows 機器に対してWindows用のモジュールが使用されていませんでした。コマンドを見ると分かりますが、Windows PCに対してumaskなどのコマンドを実行していました。

以下は Windows 用のインベントリファイルです。

[windows]
192.168.11.100

[windows:vars]
ansible_user=username
#ansible_password=
ansible_connection=winrm
ansible_port=5986
ansible_winrm_server_cert_validation=ignore
#ansible_python_interpreter=c:\Python\python



Windows PCに対しては SSH ではなく Remote Powershell を使用して接続します。
今回は inventory ファイルに誤りがあったのが原因で SSH で接続していました。たまたま Windows 10 PCで OpenSSH機能が有効化されていたためこのエラーが発生しました。


参考


SSHのパスワードに誤りがある場合は以下のエラーとなります。


winpc | UNREACHABLE!: Invalid/incorrect password: Permission denied, please try again.







Ansibleのよくある質問




個人的に独自に調査した事項をまとめています。各ベンダーとは全く関係がありません。
内容に誤りがある場合や情報が古くなっている場合があります。その場合でも修正されるとは限りません。
参考としてサイト閲覧ください。万が一誤りがあり損失等が発生しても保証しません。あくまでも自己責任でサイトを閲覧ください。